package com.daisuxia.web.util;

import static com.daisuxia.web.pojo.BorrowOrder.borrowStatusMap_shenheFail;
import static com.daisuxia.web.pojo.BorrowOrder.borrowStatusMap_shenhezhong;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.daisuxia.back.utils.SysCacheUtils;
import com.daisuxia.constant.Constant;
import com.daisuxia.web.pojo.BackConfigParams;
import com.daisuxia.web.pojo.BorrowOrder;
import com.daisuxia.web.pojo.InfoImage;
import com.daisuxia.web.pojo.InfoIndex;
import com.daisuxia.web.pojo.InfoIndexInfo;
import com.daisuxia.web.pojo.InfoNotice;
import com.daisuxia.web.pojo.Repayment;
import com.daisuxia.web.pojo.User;
import com.daisuxia.web.service.IRepaymentService;

public class IndexUtil {

	private static Logger loger = Logger.getLogger(IndexUtil.class);
	/**
	 * 获取公告
	 * @param noticeList
	 * @return
	 */
	public static Object getUserLoanLogList(List<InfoNotice> noticeList) {
		List<String> userLoanLogList = new ArrayList<String>();
		for(InfoNotice notice : noticeList){
			userLoanLogList.add(notice.getNotContent());
		}
		return userLoanLogList;
	}
	/**
	 * 获取首页图片
	 * @param infoImageList
	 * @return
	 */
	public static Object getInfoImageList(List<InfoImage> infoImageList){
		List<HashMap<String,Object>> infoImageLists = new ArrayList<HashMap<String,Object>>();
		for(InfoImage infoImage : infoImageList){
			HashMap<String,Object> map = new HashMap<String,Object>();
			map.put("url", infoImage.getUrl());
			map.put("title", infoImage.getTitle());
			map.put("sort", infoImage.getSort());
			map.put("reurl", infoImage.getReurl());
			infoImageLists.add(map);
		}
		return infoImageLists;
	}

	/**
	 * 获取金额列表
	 * @param index
	 * @return
	 */
	public static Object getAmounts(InfoIndex index) {
		List<String> amountList = new ArrayList<String>();
		Integer max = null;
		Integer min = null;
		try{
			max = Integer.parseInt(index.getAmount_max());
			min = Integer.parseInt(index.getAmount_min());
		}catch(Exception e){
			max = Constant.AMOUNT_MAX;
			min = Constant.AMOUNT_MIN;
		}
		if(max == null){
			max = Constant.AMOUNT_MAX;
		}
		if(min ==null){
			min = Constant.AMOUNT_MIN;
		}
		for(int i=min;i<=max;i=i+Constant.FOR_BASE){
			amountList.add(String.valueOf(i));
		}
		return amountList;
	}
	/**
	 * 获取金额列表
	 * @param max
	 * @return
	 */
	public static Object getAmounts(Integer min,Integer max) {
		List<String> amountList = new ArrayList<String>();
		if(1==max){
			amountList.add("0");
			amountList.add("1");
			return amountList;
		}
		boolean bool = true;
		if((max/Constant.FOR_BASE)!=0){
			bool = false;
		}
		Integer maxs = max/Constant.FOR_BASE*Constant.FOR_BASE;
		
		for(int i=min;i<=maxs;i=i+Constant.FOR_BASE){
			amountList.add(String.valueOf(i));
		}
		if(!bool){
			amountList.add(String.valueOf(max));
		}
		return amountList;
	}

	/**
	 * 获取到账金额、佣金金额
	 * @param index
	 * @return
	 */
	public static Object getInterests(InfoIndex index) {
		List<String> interestList = new ArrayList<String>();
		interestList.add(index.getAmount());
		interestList.add(index.getService_amount());
		return interestList;
	}
	/**
	 * 获取到账金额、佣金金额
	 * @param indexInfo
	 * @return
	 */
	public static Object getInterests(InfoIndexInfo indexInfo) {
		loger.info("获取到账金额、佣金金额:Rate:"+indexInfo.getRate()+" CardAmount:"+indexInfo.getCardAmount()+" AmountMin:"+indexInfo.getAmountMin());
		Integer amountMax = null;
		Double rateMax = null;
		Double rateMin = null;
		try{
			String[] rateArr = indexInfo.getRate().split(",");//目前默认7，14天的利率
			amountMax = Integer.parseInt(indexInfo.getCardAmount());
			
			if(null!=rateArr && 0<rateArr.length && rateArr.length==2){
				rateMax = Double.parseDouble(rateArr[1]);
				rateMin = Double.parseDouble(rateArr[0]);
			}else{
				rateMax = Constant.RATE_MAX;
				rateMin = Constant.RATE_MIN;
			}
		}catch(Exception e){
			amountMax = Constant.AMOUNT_MAX;
			rateMax = Constant.RATE_MAX;
			rateMin = Constant.RATE_MIN;
		}
		
		List<String> interestList = new ArrayList<String>();
		
		String amountMinRate = String.valueOf(Double.parseDouble(amountMax+"")*rateMin);
		String amountMaxRate = String.valueOf(Double.parseDouble(amountMax+"")*rateMax);
		
		interestList.add(amountMinRate.substring(0, amountMinRate.indexOf(".")));
		interestList.add(amountMaxRate.substring(0, amountMaxRate.indexOf(".")));
		return interestList;
	}
	
	/**
	 * 获取利息
	 * @param indexInfo
	 * @param user
	 * @return
	 */
	public static Object getAccrual(InfoIndexInfo indexInfo,User user,JSONArray days) {
		loger.info("获取账户管理费使用user");
		Integer amountMax = null;
		Double accrualMax = null;
		Double accrualMin = null;
		try{
			if(null!=user){
				loger.info("获取账户管理费使用userId="+user.getId()+" amountmax="+user.getAmountMax());
				loger.info("获取账户管理费使用userId="+user.getId()+" amountmax="+user.getAmountMax());
				amountMax = Integer.parseInt(user.getAmountMax());
			}
			Map<String, String> keys = SysCacheUtils.getConfigParams(BackConfigParams.SYS_FEE);
			String accrualrateTypes = keys.get("ACCRUAL_RATE");
				String accrualRateTypesArr[] = accrualrateTypes.split(";");
				for (String a : accrualRateTypesArr) {
					String accrualRates[] = a.split(":");
					if (days.get(0).toString().equals(accrualRates[0])) {//判断是否是7天
						accrualMin = Double.valueOf(accrualRates[1]);
					}else if (days.get(1).toString().equals(accrualRates[0])) {//判断是否是14天
						accrualMax = Double.valueOf(accrualRates[1]);
					}else {
						accrualMax = Constant.ACCRUAL_RATE_MAX;
						accrualMin = Constant.ACCRUAL_RATE_MIN;
					}
				}
		}catch(Exception e){
			try{
				if(null == amountMax){
					amountMax = Integer.parseInt(indexInfo.getCardAmount());
				}
			}catch(Exception e0){
				amountMax = Constant.AMOUNT_MAX;
			}
			accrualMax = Constant.ACCRUAL_RATE_MAX;
			accrualMin = Constant.ACCRUAL_RATE_MIN;
		}
		List<String>  accrualList = new ArrayList<String>();
		String creditMinRate = String.valueOf(Double.parseDouble(amountMax+"")*accrualMin);
		String creditMaxRate = String.valueOf(Double.parseDouble(amountMax+"")*accrualMax);
		accrualList.add(creditMinRate.substring(0, creditMinRate.indexOf(".")));
		accrualList.add(creditMaxRate.substring(0, creditMaxRate.indexOf(".")));
		return  accrualList;
	}
	
	/**
	 * 获取账户管理费
	 * @param indexInfo
	 * @param user
	 * @return
	 */
	public static Object getAccountManage(InfoIndexInfo indexInfo,User user,JSONArray days) {
		loger.info("获取账户管理费使用user");
		Integer amountMax = null;
		Double accountManageMax = null;
		Double accountManageMin = null;
		try{
			if(null!=user){
				loger.info("获取账户管理费使用userId="+user.getId()+" amountmax="+user.getAmountMax());
				amountMax = Integer.parseInt(user.getAmountMax());
			}
			Map<String, String> keys = SysCacheUtils.getConfigParams(BackConfigParams.SYS_FEE);
			String accountManageRateTypes = keys.get("ACCOUNT_MANAGE_RATE");
				String accountManageRateTypesArr[] = accountManageRateTypes.split(";");
				for (String a : accountManageRateTypesArr) {
					String accountManageRates[] = a.split(":");
					if (days.get(0).toString().equals(accountManageRates[0])) {//判断是否是7天
						accountManageMin = Double.valueOf(accountManageRates[1]);
					} else if (days.get(1).toString().equals(accountManageRates[0])) {//判断是否是14天
						accountManageMax = Double.valueOf(accountManageRates[1]);
					}else{
						accountManageMax = Constant.ACCOUNT_MANAGE_RATE_MAX;
						accountManageMin = Constant.ACCOUNT_MANAGE_RATE_MIN;
					}
				}
		}catch(Exception e){
			try{
				if(null == amountMax){
					amountMax = Integer.parseInt(indexInfo.getCardAmount());
				}
			}catch(Exception e0){
				amountMax = Constant.AMOUNT_MAX;
			}
			accountManageMax = Constant.ACCOUNT_MANAGE_RATE_MAX;
			accountManageMin = Constant.ACCOUNT_MANAGE_RATE_MIN;
		}
		
		List<String>  accountManageList = new ArrayList<String>();
		
		String creditMinRate = String.valueOf(Double.parseDouble(amountMax+"")*accountManageMin);
		String creditMaxRate = String.valueOf(Double.parseDouble(amountMax+"")*accountManageMax);
		
		accountManageList.add(creditMinRate.substring(0, creditMinRate.indexOf(".")));
		accountManageList.add(creditMaxRate.substring(0, creditMaxRate.indexOf(".")));
		return  accountManageList;
	}
	
	/**
	 * 获取信审查询费用
	 * @param indexInfo
	 * @param user
	 * @return
	 */
	public static Object getCreditVet(InfoIndexInfo indexInfo,User user,JSONArray days) {
		loger.info("获取信审查询费使用user");
		Integer amountMax = null;
		Double creditRateMax = null;
		Double creditRateMin = null;
		try{
			if(null!=user){
				loger.info("获取信审查询费使用userId="+user.getId()+" amountmax="+user.getAmountMax());
				amountMax = Integer.parseInt(user.getAmountMax());
			}
			Map<String, String> keys = SysCacheUtils.getConfigParams(BackConfigParams.SYS_FEE);
			String creditRateTypes = keys.get("CREDIT_RATE");
				String creditRateTypesArr[] = creditRateTypes.split(";");
				for (String c : creditRateTypesArr) {
					String creditRates[] = c.split(":");
					if (days.get(0).toString().equals(creditRates[0])) {//判断是否是7天
						creditRateMin = Double.valueOf(creditRates[1]);
					}else if (days.get(1).toString().equals(creditRates[0])) {//判断是否是14天
						creditRateMax = Double.valueOf(creditRates[1]);
					}else {
						creditRateMax = Constant.CREDIT_RATE_MAX;
						creditRateMin = Constant.CREDIT_RATE_MIN;
					}
				}
		}catch(Exception e){
			try{
				if(null == amountMax){
					amountMax = Integer.parseInt(indexInfo.getCardAmount());
				}
			}catch(Exception e0){
				amountMax = Constant.AMOUNT_MAX;
			}
			creditRateMax = Constant.CREDIT_RATE_MAX;
			creditRateMin = Constant.CREDIT_RATE_MIN;
		}
		
		List<String>  creditVetList = new ArrayList<String>();
		
		String creditMinRate = String.valueOf(Double.parseDouble(amountMax+"")*creditRateMin);
		String creditMaxRate = String.valueOf(Double.parseDouble(amountMax+"")*creditRateMax);
		
		 creditVetList.add(creditMinRate.substring(0, creditMinRate.indexOf(".")));
		 creditVetList.add(creditMaxRate.substring(0, creditMaxRate.indexOf(".")));
		return  creditVetList;
	}
	
	/**
	 * 获取到账金额、佣金金额
	 * @param indexInfo
	 * @return
	 */
	public static Object getInterests(InfoIndexInfo indexInfo,User user) {
		loger.info("获取到账金额、佣金金额使用user");
		Integer amountMax = null;
		Double rateMax = null;
		Double rateMin = null;
		try{
			if(null!=user){
				loger.info("获取到账金额、佣金金额使用userId="+user.getId()+" amountmax="+user.getAmountMax());
				amountMax = Integer.parseInt(user.getAmountMax());
			}
			String[] rateArr = indexInfo.getRate().split(",");//目前默认7，14天的利率
			
			if(0<rateArr.length && rateArr.length==2){
				rateMax = Double.parseDouble(rateArr[1]);
				rateMin = Double.parseDouble(rateArr[0]);
			}else{
				rateMax = Constant.RATE_MAX;
				rateMin = Constant.RATE_MIN;
			}
		}catch(Exception e){
			try{
				if(null == amountMax){
					amountMax = Integer.parseInt(indexInfo.getCardAmount());
				}
			}catch(Exception e0){
				amountMax = Constant.AMOUNT_MAX;
			}
			rateMax = Constant.RATE_MAX;
			rateMin = Constant.RATE_MIN;
		}
		
		List<String> interestList = new ArrayList<String>();
		
		String amountMinRate = String.valueOf(Double.parseDouble(amountMax+"")*rateMin);
		String amountMaxRate = String.valueOf(Double.parseDouble(amountMax+"")*rateMax);
		
		interestList.add(amountMinRate.substring(0, amountMinRate.indexOf(".")));
		interestList.add(amountMaxRate.substring(0, amountMaxRate.indexOf(".")));
		return interestList;
	}

	/**
	 * 获取借款日期
	 * @param index
	 * @return
	 */
	public static Object getDays(InfoIndex index){
		String[] strArr = index.getDay().split(",");
		loger.info("获取借款日期:"+strArr.toString());
		List<String> daysList = new ArrayList<String>();
		for(String string : strArr){
			daysList.add(string);
		}
		return daysList;
	}
	/**
	 * 获取认证
	 * @param pass1
	 * @param pass2
	 * @return
	 */
	public static Object getVerifyLoanPass(String pass1,String pass2){
		loger.info("获取认证getVerifyLoanPass-pass1="+pass1+" pass2="+pass2);
		if(StringUtils.isNotBlank(pass1)&& StringUtils.isNotBlank(pass2)){
			if(pass1.equals(pass2)){//认证完成(需要完成必填项的5项)
				return 1;
			}
		}
		return 0;
	}
	
	/**
	 * 2.2.0版本认证
	 * @param string
	 * @param string2
	 * @return
	 */
	public static Object getVerifyLoanPass2(String authSum, String authCount,String authBank) {
		loger.info("获取认证getVerifyLoanPass2-authSum="+authSum+" authCount="+authCount+ "authBank="+authBank);
		if(StringUtils.isNotBlank(authSum)&& StringUtils.isNotBlank(authCount)){
			if(Integer.valueOf(authSum)==4 && Integer.valueOf(authBank) == 0){//认证完成(完成除银行卡的必填项4项外)
				return 1;
			}if (authSum.equals(authCount)) {
				return 1;
			}
		}
		return 0;
	}
	
	/**
	 * 获取用户借款信息
	 * @param bo
	 * @return
	 */
	public static String getLoanInfos(InfoIndexInfo indexInfo,BorrowOrder bo,IRepaymentService repaymentService){
		loger.info("getLoanInfos-indexInfo:"+indexInfo.toString());
		loger.info("getLoanInfos-BorrowOrder:"+bo.toString());
		Map<String, Object> reMap = new HashMap<String, Object>();
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		Map<String, String> map = new HashMap<String, String>();
		Map<String, String> buttonMap = null;//当审核拒绝时，显示button
		String intoMoney = null;//借款金额
		String loanEndTime = null;//loanEndTime 还款时间
		String lastRepaymentD = null;//lastRepaymentD 剩余还款天数
		String header_tip = "申请提交成功";
		map.put("tag", "0");
		map.put("title", "申请提交成功" + DateUtil.getDateFormat(bo.getCreatedAt(),"yyyy-MM-dd HH:mm"));
		map.put("body", "申请借款" + (bo.getMoneyAmount() / 100.00) + "元，期限" + bo.getLoanTerm() + BorrowOrder.loanMethed.get(bo.getLoanMethod()) + "，手续费" + (bo.getLoanInterests() / 100.00) + "元");
		list.add(map);
		map = new HashMap<String, String>();
		// 如果是 待初审(待机审)、初审通过(机审通过)，待复审  显示审核中
//		if(bo.getStatus().equals(BorrowOrder.STATUS_DCS) || bo.getStatus().equals(BorrowOrder.STATUS_CSTG)){
		loger.info("bo.getStatus="+bo.getStatus());
		if(borrowStatusMap_shenhezhong.containsKey(bo.getStatus())){
		
			map.put("tag", "1");
			map.put("title", "审核中");
			map.put("body", "已进入风控审核状态，请您耐心等待");
			list.add(map);
			header_tip = "风控审核中，请您耐心等待";
		}
		// 如果是 机审拒绝、初审驳回、复审驳回  显示审核不通过
//		else if(bo.getStatus().equals(BorrowOrder.STATUS_JSJJ) || bo.getStatus().equals(BorrowOrder.STATUS_CSBH) || bo.getStatus().equals(BorrowOrder.STATUS_FSBH)){
		else if(borrowStatusMap_shenheFail.containsKey(bo.getStatus())){
			map.put("tag", "2");
			String shTimeStr=bo.getVerifyTrialTime()==null?"":DateUtil.getDateFormat(bo.getVerifyTrialTime(),"yyyy-MM-dd HH:mm");
			if(bo.getVerifyReviewTime()!=null){
				shTimeStr=DateUtil.getDateFormat(bo.getVerifyReviewTime(),"yyyy-MM-dd HH:mm");
			}
			map.put("title", "审核不通过"+shTimeStr);
			// 如果是 机审拒绝显示初审备注
//			if(bo.getStatus().equals(BorrowOrder.STATUS_JSJJ)){
//				map.put("body", bo.getVerifyTrialRemark());
//			}
//			// 如果是 初审驳回  显示初审备注
//			else
				if(bo.getStatus().equals(BorrowOrder.STATUS_CSBH)){
					if(bo.getVerifyTrialUser().equals("机审")){
						map.put("body", "信用评分不足");
					}else{
						map.put("body", bo.getVerifyTrialRemark());
					}
					//<--
					Date vDate = DateUtil.addDay(bo.getVerifyTrialTime(), Constant.DEFAULT_DAYS);//默认再借时间
					String scdDays = DateUtil.getDateFormat(DateUtil.addDay(new Date(),Constant.DEFAULT_DAYS), "yyyy-MM-dd");
					if(null!=vDate){
						scdDays = DateUtil.getDateFormat(vDate, "yyyy-MM-dd");
					}
					map.put("days", scdDays);
					//-->
				buttonMap = new HashMap<String, String>();
				buttonMap.put("msg", Constant.BUTTON_MSG);
				buttonMap.put("id", indexInfo.getUserId()+"");
			}
			// 如果是 复审拒绝  显示复审备注
			else if(bo.getStatus().equals(BorrowOrder.STATUS_FSBH)){
				map.put("body", bo.getVerifyReviewRemark());
				buttonMap = new HashMap<String, String>();
				buttonMap.put("msg", Constant.BUTTON_MSG);
				buttonMap.put("id", indexInfo.getUserId()+"");
				//<--
				Date vDate = DateUtil.addDay(bo.getVerifyReviewTime(), Constant.DEFAULT_DAYS);//默认再借时间
				String scdDays = DateUtil.getDateFormat(DateUtil.addDay(new Date(),Constant.DEFAULT_DAYS), "yyyy-MM-dd");
				if(null!=vDate){
					scdDays = DateUtil.getDateFormat(vDate, "yyyy-MM-dd");
				}
				map.put("days", scdDays);
				//-->
			}else if(bo.getStatus().equals(BorrowOrder.STATUS_FKBH)){
				map.put("body", bo.getVerifyLoanRemark());
				buttonMap = new HashMap<String, String>();
				buttonMap.put("msg", Constant.BUTTON_MSG);
				buttonMap.put("id", indexInfo.getUserId()+"");
				//<--
				Date vDate = DateUtil.addDay(bo.getVerifyLoanTime(), Constant.DEFAULT_DAYS);//默认再借时间
				String scdDays = DateUtil.getDateFormat(DateUtil.addDay(new Date(),Constant.DEFAULT_DAYS), "yyyy-MM-dd");
				if(null!=vDate){
					scdDays = DateUtil.getDateFormat(vDate, "yyyy-MM-dd");
				}
				map.put("days", scdDays);
				//-->
			}
			else{
				map.put("body", "经审核您不符合借款要求");
			}
			list.add(map);
			
			header_tip = "审核未通过";
			
		}else{
			map.put("tag", "0");
			map.put("title", "审核通过" + DateUtil.getDateFormat(bo.getVerifyReviewTime(),"yyyy-MM-dd HH:mm"));
			map.put("body", "恭喜通过风控审核");
			list.add(map);
			header_tip = "审核通过";
			map = new HashMap<String, String>();
			if(bo.getStatus().equals(BorrowOrder.STATUS_FSTG)){
				map.put("tag", "1");
				map.put("title", "打款审核中");
				map.put("body", "已进入打款审核状态，请您耐心等待");
				list.add(map);
				header_tip = "打款审核中，请耐心等待";
			}
			else if(bo.getStatus().equals(BorrowOrder.STATUS_FKZ)||bo.getStatus().equals(BorrowOrder.STATUS_FKSB)){
				map.put("tag", "1");
				map.put("title", "打款中");
				map.put("body", "已进入打款流程，请您耐心等待");
				list.add(map);
				header_tip = "打款中，请耐心等待";
			}
			else if(bo.getStatus().equals(BorrowOrder.STATUS_FKBH)){
				map.put("tag", "2");
				map.put("title", "打款审核不通过");
				map.put("body", bo.getVerifyLoanRemark());
				list.add(map);
				header_tip = "审核未通过";
				buttonMap = new HashMap<String, String>();
				buttonMap.put("msg", Constant.BUTTON_MSG);
				buttonMap.put("id", indexInfo.getUserId()+"");
				//<--
				Date vDate = DateUtil.addDay(bo.getVerifyLoanTime(), Constant.DEFAULT_DAYS);//默认再借时间
				String scdDays = DateUtil.getDateFormat(DateUtil.addDay(new Date(),Constant.DEFAULT_DAYS), "yyyy-MM-dd");
				if(null!=vDate){
					scdDays = DateUtil.getDateFormat(vDate, "yyyy-MM-dd");
				}
				map.put("days", scdDays);
				//-->
			}
//			else if(bo.getStatus().equals(BorrowOrder.STATUS_FKSB)){
//				map.put("tag", "1");
//				map.put("title", "打款失败");
//				map.put("body", "打款失败，详情请联系客服");
//				list.add(map);
//				header_tip = "打款失败，请联系客服";
//			}
			else{
				map.put("tag", "0");
				map.put("title", "打款成功");
				map.put("body", "打款至银行卡尾号为"+indexInfo.getBankNo().substring(indexInfo.getBankNo().length()-4, indexInfo.getBankNo().length()));
				list.add(map);
				map = new HashMap<String, String>();
				map.put("tag", "3");
				Map<String, Object> mapT = new HashMap<String, Object>();
				mapT.put("assetOrderId", bo.getId());
				Repayment repayment = repaymentService.findOneRepayment(mapT);
				Long moneyAmount = repayment.getRepaymentAmount() - repayment.getRepaymentedAmount();
				moneyAmount = moneyAmount < 0 ? 0 : moneyAmount;
				intoMoney = String.valueOf(moneyAmount / 100.00);
				loanEndTime = DateUtil.getDateFormat(repayment.getRepaymentTime(),"yyyy-MM-dd");
				try {
					lastRepaymentD = String.valueOf(DateUtil.daysBetween(new Date(), repayment.getRepaymentTime()));
				} catch (ParseException e) {
					lastRepaymentD = "0";
					loger.error("计算剩余还款天数错误2 repayId=" + repayment.getId(), e);
				}
				if(bo.getStatus().equals(BorrowOrder.STATUS_HKZ) || bo.getStatus().equals(BorrowOrder.STATUS_BFHK)){
					int days = 14;
					try{
						days = DateUtil.daysBetween(new Date(), repayment.getRepaymentTime());
						lastRepaymentD = String.valueOf(days);
					}catch(Exception e){
						lastRepaymentD = "0";
						loger.error("计算剩余还款天数错误 repayId=" + repayment.getId(), e);
					}
					map.put("title", days + "天后还款");
					map.put("body", "请于" + DateUtil.getDateFormat(repayment.getRepaymentTime(),"yyyy-MM-dd") + "前将还款金额存入银行卡中");
				}
				else if(bo.getStatus().equals(BorrowOrder.STATUS_BFHK)){
					map.put("title", "部分还款");
					map.put("body", "请于" + DateUtil.getDateFormat(repayment.getRepaymentTime(),"yyyy-MM-dd") + "前将还款金额存入银行卡中");
				}
				else if(bo.getStatus().equals(BorrowOrder.STATUS_YYQ)){
					map.put("title", "已逾期");
					map.put("body", "您的借款已逾期，请尽快完成还款操作");
				}
				else if(bo.getStatus().equals(BorrowOrder.STATUS_YHZ)){
					map.put("title", "已坏账");
					map.put("body", "您的借款已坏账，详情请联系客服");
				}
				else{// if(bo.getStatus().equals(BorrowOrder.STATUS_YHK))
					map.put("title", "已还款");
					map.put("body", "恭喜还款成功，又积攒了一份信用");
				}
				list.add(map);
				header_tip = "还款中，请按时还款";
			}
		}
		
		Collections.reverse(list);//倒序排列
		reMap.put("lists", list);
		reMap.put("header_tip", header_tip);
		if(null!=buttonMap){
			reMap.put("button", buttonMap);
		}
		if(StringUtils.isNotBlank(intoMoney)){
			reMap.put("intoMoney", intoMoney);
		}
		if(StringUtils.isNotBlank(loanEndTime)){
			reMap.put("loanEndTime", loanEndTime);
		}
		if(null != lastRepaymentD){
			reMap.put("lastRepaymentD", lastRepaymentD);
		}
		return JSONUtil.beanToJson(reMap);
	}
	
	
	//贷速侠可能会用到
	/**
	 * 获取利息
	 * @param indexInfo
	 * @param user
	 * @return
	 */
	public static Object getAccrualDays(InfoIndex index) {
		loger.info("获取账户管理费使用user");
		Integer amountMax = null;
		Double accrualMax = null;
		Double accrualMin = null;
		try{
			
			Map<String, String> keys = SysCacheUtils.getConfigParams(BackConfigParams.SYS_FEE);
			String accrualrateTypes = keys.get("ACCRUAL_RATE");
				String accrualRateTypesArr[] = accrualrateTypes.split(";");
				for (String a : accrualRateTypesArr) {
					String accrualRates[] = a.split(":");
					if (index.getDay().toString().equals(accrualRates[0])) {//判断是否是7天
						accrualMin = Double.valueOf(accrualRates[1]);
					}else if (index.getDay().toString().equals(accrualRates[0])) {//判断是否是14天
						accrualMax = Double.valueOf(accrualRates[1]);
					}else {
						accrualMax = Constant.ACCRUAL_RATE_MAX;
						accrualMin = Constant.ACCRUAL_RATE_MIN;
					}
				}
		}catch(Exception e){
			try{
				if(null == amountMax){
					amountMax = Integer.parseInt(index.getCard_amount());
				}
			}catch(Exception e0){
				amountMax = Constant.AMOUNT_MAX;
			}
			accrualMax = Constant.ACCRUAL_RATE_MAX;
			accrualMin = Constant.ACCRUAL_RATE_MIN;
		}
		List<String>  accrualList = new ArrayList<String>();
		String creditMinRate = String.valueOf(Double.parseDouble(amountMax+"")*accrualMin);
		String creditMaxRate = String.valueOf(Double.parseDouble(amountMax+"")*accrualMax);
		accrualList.add(creditMinRate.substring(0, creditMinRate.indexOf(".")));
		accrualList.add(creditMaxRate.substring(0, creditMaxRate.indexOf(".")));
		return  accrualList;
	}
	
	
	/**
	 * 获取账户管理费
	 * @param indexInfo
	 * @param user
	 * @return
	 */
	public static Object getAccountManageDays(InfoIndex index) {
		loger.info("获取账户管理费使用user");
		Integer amountMax = null;
		Double accountManageMax = null;
		Double accountManageMin = null;
		try{
		
			Map<String, String> keys = SysCacheUtils.getConfigParams(BackConfigParams.SYS_FEE);
			String accountManageRateTypes = keys.get("ACCOUNT_MANAGE_RATE");
				String accountManageRateTypesArr[] = accountManageRateTypes.split(";");
				for (String a : accountManageRateTypesArr) {
					String accountManageRates[] = a.split(":");
					if (index.getDay().toString().equals(accountManageRates[0])) {//判断是否是7天
						accountManageMin = Double.valueOf(accountManageRates[1]);
					} else if (index.getDay().toString().equals(accountManageRates[0])) {//判断是否是14天
						accountManageMax = Double.valueOf(accountManageRates[1]);
					}else{
						accountManageMax = Constant.ACCOUNT_MANAGE_RATE_MAX;
						accountManageMin = Constant.ACCOUNT_MANAGE_RATE_MIN;
					}
				}
		}catch(Exception e){
			try{
				if(null == amountMax){
					amountMax = Integer.parseInt(index.getCard_amount());
				}
			}catch(Exception e0){
				amountMax = Constant.AMOUNT_MAX;
			}
			accountManageMax = Constant.ACCOUNT_MANAGE_RATE_MAX;
			accountManageMin = Constant.ACCOUNT_MANAGE_RATE_MIN;
		}
		
		List<String>  accountManageList = new ArrayList<String>();
		
		String creditMinRate = String.valueOf(Double.parseDouble(amountMax+"")*accountManageMin);
		String creditMaxRate = String.valueOf(Double.parseDouble(amountMax+"")*accountManageMax);
		
		accountManageList.add(creditMinRate.substring(0, creditMinRate.indexOf(".")));
		accountManageList.add(creditMaxRate.substring(0, creditMaxRate.indexOf(".")));
		return  accountManageList;
	}
	
	/**
	 * 获取信审查询费用
	 * @param indexInfo
	 * @param user
	 * @return
	 */
	public static Object getCreditVetDays(InfoIndex index) {
		loger.info("获取信审查询费使用user");
		Integer amountMax = null;
		Double creditRateMax = null;
		Double creditRateMin = null;
		try{
			
			Map<String, String> keys = SysCacheUtils.getConfigParams(BackConfigParams.SYS_FEE);
			String creditRateTypes = keys.get("CREDIT_RATE");
				String creditRateTypesArr[] = creditRateTypes.split(";");
				for (String c : creditRateTypesArr) {
					String creditRates[] = c.split(":");
					if (index.getDay().toString().equals(creditRates[0])) {//判断是否是7天
						creditRateMin = Double.valueOf(creditRates[1]);
					}else if (index.getDay().toString().equals(creditRates[0])) {//判断是否是14天
						creditRateMax = Double.valueOf(creditRates[1]);
					}else {
						creditRateMax = Constant.CREDIT_RATE_MAX;
						creditRateMin = Constant.CREDIT_RATE_MIN;
					}
				}
		}catch(Exception e){
			try{
				if(null == amountMax){
					amountMax = Integer.parseInt(index.getCard_amount());
				}
			}catch(Exception e0){
				amountMax = Constant.AMOUNT_MAX;
			}
			creditRateMax = Constant.CREDIT_RATE_MAX;
			creditRateMin = Constant.CREDIT_RATE_MIN;
		}
		
		List<String>  creditVetList = new ArrayList<String>();
		
		String creditMinRate = String.valueOf(Double.parseDouble(amountMax+"")*creditRateMin);
		String creditMaxRate = String.valueOf(Double.parseDouble(amountMax+"")*creditRateMax);
		
		 creditVetList.add(creditMinRate.substring(0, creditMinRate.indexOf(".")));
		 creditVetList.add(creditMaxRate.substring(0, creditMaxRate.indexOf(".")));
		return  creditVetList;
	}
}
